package com.ruoyi.project.xkx.order.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.service.ISysUserService;
import com.ruoyi.project.xkx.order.domain.ClassStudent;
import com.ruoyi.project.xkx.order.domain.YsOrder;
import com.ruoyi.project.xkx.school.domain.XkxClassStudent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.catalina.User;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.xkx.order.domain.XkOrder;
import com.ruoyi.project.xkx.order.service.IXkOrderService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 消课订单Controller
 * 
 * @author 闫阳光
 * @date 2021-05-13
 */
@RestController
@RequestMapping("/order/xkOrder")
@Api(tags="消课订单")
public class XkOrderController extends BaseController
{
    @Autowired
    private IXkOrderService xkOrderService;


    @GetMapping("/list/{current}/{limit}")
    @ApiOperation("消课订单列表")
    public AjaxResult list(@PathVariable Integer current,@PathVariable Integer limit,Integer userId,String xkDate){
        Page<XkOrder> list = xkOrderService.getXkOrderListByPage1(new Page<YsOrder>(current,limit),userId,xkDate);
        return AjaxResult.success(list);
    }

    @GetMapping("/getStudentHours")
    @ApiOperation("查询班级学生剩余课时")
    public AjaxResult getStudent(Integer classId){
        List<XkxClassStudent> result = xkOrderService.getStudentHours(classId);
        return AjaxResult.success("成功",result);
    }

    @GetMapping("/getTeacherList")
    @ApiOperation("任课老师数据")
    public AjaxResult getTeacherList(){
        List<SysUser> teacherList = xkOrderService.getTeacherList();
        return AjaxResult.success("教师集合",teacherList);
    }

    /**
     * 导出消课订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:xkOrder:export')")
    @Log(title = "消课订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(XkOrder xkOrder)
    {
        List<XkOrder> list = xkOrderService.getXkOrderListByPage(xkOrder);
        ExcelUtil<XkOrder> util = new ExcelUtil<XkOrder>(XkOrder.class);
        return util.exportExcel(list, "消课订单数据");
    }

    /**
     * 新增消课订单
     */
    //@PreAuthorize("@ss.hasPermi('order:xkOrder:add')")
    @Log(title = "消课订单", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("生成消课订单　功能使用者:任课老师")
    public AjaxResult add(@RequestBody XkOrder xkOrder)
    {
        return toAjax(xkOrderService.insertXkOrder(xkOrder));
    }

}
